package com.artifact.mit.mypoint.fragment.app;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.artifact.mit.mypoint.R;
import com.artifact.mit.mypoint.service.async.ProductListAsync;

public class ProductListFragment extends ListFragment {

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return inflater.inflate(R.layout.catalogue_content_detail, null);
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		new ProductListAsync(getActivity(), getListView()).execute(getArguments().getString("catalogId"));
	}
	
	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {
		FragmentTransaction f = this.getFragmentManager()
				.beginTransaction();
		ProductDetailHtmlFragment da = new ProductDetailHtmlFragment();
		Bundle bundle = new Bundle();
		bundle.putInt("index", position);
		da.setArguments(bundle);
		f.replace(R.id.main_frame, da);
		f.commit();
	}
}
